using System;
using System.Collections.Generic;
using System.Text;
using TidhiGanitam.DataModel;


namespace TidhiGanitam.DataModel
{
    public class MathHelper
    {
        private static double GetFloorValue(double Value)
        {
            Value = Math.Abs(Value);
            double dRetVal = Math.Floor(Value);
            return dRetVal;
        }
        public static double GetDegrees(double Value)
        {
            Value = Math.Abs(Value);
            double dRetVal = MathHelper.GetFloorValue(Value);
            double dMin = MathHelper._getminutes(Value);
            if (dMin > 59) { dRetVal++;}
            return dRetVal;
        }
        public static double GetMinutes(double Value)
        {
            double dMin = 0d;
            dMin = MathHelper._getminutes(Value);
            if (dMin > 59) { return 0d; }
            return dMin;
        }
        public static double GetSeconds(double Value)
        {
            double dSec = 0d;
            dSec = MathHelper._getseconds(Value);
            if (dSec > 59) { return 0d; }
            return dSec;
        }
        public static double GetMilliSeconds(double Value)
        {
            double dMlSec = MathHelper._getmilliseconds(Value);
            if (dMlSec > 59) { return 0d; }
            return dMlSec;
        }
        private static double _getminutes(double Value)
        {
            double dSec = MathHelper._getseconds(Value);
            Value = Math.Abs(Value);
            double dFloor = MathHelper.GetFloorValue(Value);
            double dMin = System.Math.Floor((Value - dFloor) * 60);
            if (dSec > 59) { dMin++; }
            return dMin;
 
        }
        private static double _getseconds(double Value)
        {
            double dMlSec = MathHelper._getmilliseconds(Value);//
            Value = Math.Abs(Value);
            double dSec = 0d;
            double dFloor = MathHelper.GetFloorValue(Value);
            double dMinAll = (Value - dFloor) * 60;
            double dMin = MathHelper.GetFloorValue(dMinAll);
            //dSec = System.Math.Round((dMinAll - dMin) * 60);
            dSec = MathHelper.GetFloorValue((dMinAll - dMin) * 60);//
            if (dMlSec > 59) { dSec++; }                            //
            return dSec;
        }
        private static double _getmilliseconds(double Value)
        {
            Value = Math.Abs(Value);
            double dMlSec = 0d;
            double dFloor = MathHelper.GetFloorValue(Value);
            double dMinAll = (Value - dFloor) * 60;
            double dMin = MathHelper.GetFloorValue(dMinAll);
            double dSecAll = (dMinAll - dMin) * 60;
            double dSec = MathHelper.GetFloorValue(dSecAll);
            dMlSec = System.Math.Round((dSecAll - dSec) * 60);
            //dMlSec = MathHelper.GetFloorValue((dSecAll - dSec) * 60);
            return dMlSec; 
        }
        public static int GetThousandDigit(int Year)
        {
            return (int)Year / 1000;
        }
        public static int GetHundredDigit(int Year)
        {
            int iThousandDigit = (int)Year / 1000;
            return (int)((Year - (iThousandDigit * 1000)) / 100);
        }
        public static int GetTensDigit(int Year)
        {
            int ThousandDigit = (int)Year / 1000;
            int HundredDigit = (int)((Year - (ThousandDigit * 1000)) / 100);
            return (int)((Year - (ThousandDigit * 1000 + HundredDigit * 100)) / 10); 
        }
        public static int GetDigit(int Year)
        {
            int ThousandDigit = (int)Year / 1000;
            int HundredDigit = (int)((Year - (ThousandDigit * 1000)) / 100);
            int TensDigit = (int)((Year - (ThousandDigit * 1000 + HundredDigit * 100)) / 10);
            return (int)Year % 10;
        }
    }
}
